classdef stageThree < dynamicprops
    
    
    properties
        handles;
        
        stageAmount;
        stageTracking;
        assignedStageTracking;
        assignedAmount;
        
        filterGain;
        
        plotTracking;
        
        actualPoles;
        actualZeros;
        
        currentStageID;
        
        imageSallenKeyLP;
        imageSallenKeyHP;
        imageRauchBR;
        imageRauchBP;
        imageUniversal;
        imageSedraLP;
        imageSedraHP;
        imageInt;
        imageDer;
        imageInversor;
        imageNoInversor;

    end
    
    methods
       %%
        function main = stageThree(stageTWO)
            
           hfig = hgload('stageTHREEgui.fig'); % load 'GUIDE generated' Figure.
           main.handles = guihandles(hfig); % get figure handles.
           movegui(hfig,'center');   % sets Figure position.
           
           stageThreeCallbacks(main);
           
           main.stageAmount = stageTWO.stageAmount;
           main.stageTracking = stageTWO.stageTracking;
           main.assignedAmount = 0; 
                     
           for index = 1:main.stageAmount
              
               oldStage = [ 'stage' num2str(main.stageTracking{index,1})];
               stageToAdd = ['stage' num2str(main.stageTracking{index,1})];
               stTracking = main.addprop(stageToAdd);
               %main.stageTracking{index, 2} = stTracking;
               main.(stageToAdd) = newStage();
               main.(stageToAdd) = stageTWO.(oldStage);              

           end
           
           main.filterGain{1} = stageTWO.finalFilter.filterGain;
           main.filterGain{2} = 0;  %Is assigned or not
           
           updateStageList(main);
           
           if main.filterGain{1} ~= 1 && main.filterGain{2}==0
               stringToList = get(main.handles.list_stages, 'String');
               listSize = size(stringToList);
               listSize = listSize(1);
               stringToList{listSize+1} = 'Independent gain';
               set(main.handles.list_stages,'Value',1); %Avoids "error" when repopulating LISTBOX
               set(main.handles.list_stages, 'String', stringToList);   % Repopulates listbox
           end
           
           main.currentStageID = 1;
           main.actualPoles = max(size(main.stage1.stagePoles));
           main.actualZeros = max(size(main.stage1.stageZeros));
           
           updateActualPolesList(main, main.currentStageID);
           updateActualZerosList(main, main.currentStageID);
           
           main.imageSallenKeyLP = imread('SallenKeyLP.jpg');
           main.imageSallenKeyHP = imread('SallenKeyHP.jpg');
           main.imageSedraLP = imread('SedraLP.jpg');
           main.imageSedraHP = imread('SedraHP.jpg');
           main.imageUniversal = imread('celdaUniversal.jpg');
           main.imageRauchBR = imread('rauchBR.jpg');
           main.imageRauchBP = imread('rauchBP.jpg');
           main.imageInt = imread('imageInt.jpg');
           main.imageDer = imread('imageDer.jpg');
           main.imageInversor = imread('inversor.jpg');
           main.imageNoInversor = imread('noInversor.jpg');
           
           hold(main.handles.axes_gain);
           hold(main.handles.axes_phase);
           hold(main.handles.axes_pzmap);
           set(main.handles.axes_gain, 'XScale', 'log');
           set(main.handles.axes_phase, 'XScale', 'log');
           set(main.handles.axes_pzmap, 'XScale', 'linear');
           
           for index = 1 : main.stageAmount
               stageToPlot = ['stage' num2str(main.stageTracking{index,1})];
               [gainHandle, phaseHandle, poleHandle, zeroHandle] = doFigures(main, main.(stageToPlot).stageTransferFunction);
               main.plotTracking{index, 1} = gainHandle; 
               set(main.plotTracking{index, 1}, 'Visible', 'Off');
               main.plotTracking{index, 2} = phaseHandle;
               set(main.plotTracking{index, 2}, 'Visible', 'Off');
               main.plotTracking{index, 3} = poleHandle;
               set(main.plotTracking{index, 3}, 'Visible', 'Off');
               main.plotTracking{index, 4} = zeroHandle;
               set(main.plotTracking{index, 4}, 'Visible', 'Off');
               
               main.plotTracking{index, 5} = main.stageTracking{index,1};
           end
           
           set(main.plotTracking{1, 1}, 'Visible', 'On');
           set(main.plotTracking{1, 2}, 'Visible', 'On');
           set(main.plotTracking{1, 3}, 'Visible', 'On');
           set(main.plotTracking{1, 4}, 'Visible', 'On');
           
           initTable(main);
           
           
           
           
        end
        
        %%
        function list_stages_callback(main, varargin)
           
           selectedRow = getSelectedItem(main, 'list_stages');
           
           if selectedRow==main.stageAmount+1
               
           else
           
           main.currentStageID = main.stageTracking{selectedRow,1};
            
           stageToGet = ['stage' num2str(main.currentStageID)];
            
           main.actualPoles = max(size(main.(stageToGet).stagePoles));
           main.actualZeros = max(size(main.(stageToGet).stageZeros));
           
           updateActualPolesList(main, main.currentStageID);
           updateActualZerosList(main, main.currentStageID);
           
           for index = 1 : (main.assignedAmount+main.stageAmount)
               
                if main.plotTracking{index, 5} == main.currentStageID
                    set(main.plotTracking{index, 1}, 'Visible', 'On');
                    set(main.plotTracking{index, 2}, 'Visible', 'On');
                    set(main.plotTracking{index, 3}, 'Visible', 'On');
                    set(main.plotTracking{index, 4}, 'Visible', 'On');
                else
                    set(main.plotTracking{index, 1}, 'Visible', 'Off');
                    set(main.plotTracking{index, 2}, 'Visible', 'Off');
                    set(main.plotTracking{index, 3}, 'Visible', 'Off');
                    set(main.plotTracking{index, 4}, 'Visible', 'Off');
                end
                    
           end
           end
           
           
            
        end
        
        %%
        function btn_automatic_callback(main, varargin)
            
            selectedRow = getSelectedItem(main, 'list_stages');
            
            if selectedRow == main.stageAmount+1
                if main.filterGain{1} <1
                    main.filterGain{3} = 'inversor';
                    [R1, R2] = inversorGain(main.filterGain{1});
                    main.filterGain{4}=R1;
                    main.filterGain{5}=R2;
                    showImage(main, 7, 0);
                    showComponentValues(main, 0);
                    
                else
                    main.filterGain{3} = 'no inversor';
                    [R1, R2] = notInversorGain(main.filterGain{1});
                    main.filterGain{4}=R1;
                    main.filterGain{5}=R2;
                    showImage(main, 8, 0);
                    showComponentValues(main, 0);
                end
                
                main.filterGain{2} = 1;
                
                updateStageList(main);
                
                updateCellList(main);

            else
            
            stageToGet = ['stage' num2str(main.stageTracking{selectedRow,1})];
            
            stageType = obtainStageType (main.(stageToGet).stagePoles, main.(stageToGet).stageZeros);
            
            main.(stageToGet).stageCircuit = bestStageCircuit (main.(stageToGet).stagePoles, main.(stageToGet).stageZeros, stageType);
            
            switch main.(stageToGet).stageCircuit
                case 1  % Sallen Key
                    error = 1;
                    
                    [R1, R2, C1, C2, Ra, Rb, error] = obtainSallenKey(main.(stageToGet), stageType);
                    if error == 0
                        
                    assignValues(main.(stageToGet), stageType, R1, R2, 0, 0, 0, 0, 0, 0, Ra, Rb, C1, C2, 0);
                    
                    showImage(main, 1, stageType);
                    showComponentValues(main, main.(stageToGet));
                    showSensibility(main, main.(stageToGet));
                    else
                        errordlg('Error: No se puede implementar la etapa con la celda elegida (Sallen Key)', 'Error');
                    end
                case 2  %Sedra
                    error = 1;

                    [R1, R2, Rb, Comp1, Comp21, Comp22, Comp3, Comp41, Comp42, error]=obtainSedra (main.(stageToGet), stageType);
                    
                    if error == 0

                        if stageType == 2
                        
                        assignValues(main.(stageToGet), stageType, R1, R2, Comp3, Comp22, Comp21, 0,0, 0, 0, Rb, Comp42, Comp41, Comp1);
                   
                        showImage(main, 2, stageType);

                        elseif stageType == 3
                        
                        assignValues(main.(stageToGet), stageType, R1, R2, Comp42, Comp41, Comp1, 0, 0, 0, 0, Rb, Comp3, Comp22, Comp21);
                        
                        showImage(main, 2, stageType);

                        end
                    
                        showComponentValues(main, main.(stageToGet));
                        showSensibility(main, main.(stageToGet));
                    else
                        errordlg('Error: No se puede implementar la etapa con la celda elegida (Sedra)', 'Error');
                    end
                case 3  %Universal
                                        
                    error = 1;
                    [componentArray, error]=obtainUniversal(main.(stageToGet),stageType);
                    if error == 0
                    R1=componentArray(1);
                    R2=componentArray(2);
                    R3=componentArray(3);
                    R4=componentArray(4);
                    R5=componentArray(5);
                    R6=componentArray(6);
                    R7=componentArray(7);
                    R8=componentArray(8);
                    C1=componentArray(9);
                    C2=componentArray(10);
                    
                    assignValues(main.(stageToGet), stageType, R1, R2, R3, R4, R5, R6, R7, R8, 0, 0, C1, C2, 0);
                    
                    showImage(main, 3, stageType);
                    showComponentValues(main, main.(stageToGet));
                    showSensibility(main, main.(stageToGet));
                    else
                        errordlg('Error: No se puede implementar la etapa con la celda elegida (Universal)', 'Error');
                    end

                    
                case 4  %Rauch
                    
                     error = 1;
                    
                     if stageType == 4
                        [C1, C2, C3, R1, Ra, Rb, error] = obtainRauch(main.(stageToGet), stageType);
                        if error == 0
                        assignValues(main.(stageToGet), stageType, R1, R1, 0, 0, 0, 0, 0, 0, Ra, Rb, C1, C2, C3);
                    
                        showImage(main, 4, stageType);
                        else
                        errordlg('Error: No se puede implementar la etapa con la celda elegida (Universal)', 'Error');
                        end
                            
                     elseif stageType == 1
                        [R1, R2, R3, C1, Ra, Rb, error] = obtainRauch(main.(stageToGet), stageType);
                        
                        if error == 0
                        assignValues(main.(stageToGet), stageType, R1, R2, R3, 0, 0, 0, 0, 0, Ra, Rb, C1, C1, 0);
                    
                        showImage(main, 4, stageType);
                        else
                        errordlg('Error: No se puede implementar la etapa con la celda elegida (Universal)', 'Error');
                        end
                      else
                        errordlg('Error: No se puede implementar la etapa con la celda elegida (Rauch)', 'Error');
                    end
                     
                    if error == 0
                    showComponentValues(main, main.(stageToGet));
                    showSensibility(main, main.(stageToGet));
                    end
                    
                case 5  %Integrador
                    
                    [Ra, Rb, C1]=obtainIntegrator(main.(stageToGet));
                    
                    assignValues(main.(stageToGet), stageType, 0, 0, 0, 0, 0, 0, 0, 0, Ra, Rb, C1, 0, 0);
                    
                    showComponentValues(main, main.(stageToGet));
                    showSensibility(main, main.(stageToGet));
                    
                    showImage(main, 5, stageType);
                    
                    error = 0;  %Provisorio
                    
                    
                case 6  %Derivador
                    
                    [Ra, Rb, C1] = obtainDifferentiator(main.(stageToGet));
                    
                    assignValues(main.(stageToGet), stageType, 0, 0, 0, 0, 0, 0, 0, 0, Ra, Rb, C1, 0, 0);
                    
                    showComponentValues(main, main.(stageToGet));
                    showSensibility(main, main.(stageToGet));
                    
                    showImage(main, 6, stageType);
                    error = 0;  %Provisorio
            end
            
            if error == 0
                main.assignedAmount = main.assignedAmount + 1;
            
                main.assignedStageTracking{main.assignedAmount,1} = main.stageTracking{selectedRow,1};   
                main.assignedStageTracking{main.assignedAmount,2} = main.stageTracking{selectedRow,2};
            
                        
            for index = selectedRow : main.stageAmount-1
                main.stageTracking{index,1}=main.stageTracking{index+1,1};
                main.stageTracking{index,2}=main.stageTracking{index+1,2};
            end
            
            main.stageAmount = main.stageAmount - 1;
            
            updateCellList(main);
            
            updateStageList(main);
            
            if main.filterGain{1} ~= 1 && main.filterGain{2}==0
               stringToList = get(main.handles.list_stages, 'String');
               listSize = size(stringToList);
               listSize = listSize(1);
               stringToList{listSize+1} = 'Independent gain';
               set(main.handles.list_stages,'Value',1); %Avoids "error" when repopulating LISTBOX
               set(main.handles.list_stages, 'String', stringToList);   % Repopulates listbox
           end
            
            stringToList = {};
            set(main.handles.list_actualPoles, 'String', stringToList);
            set(main.handles.list_actualZeros, 'String', stringToList);
            end
            end % EN of idpt stage gain
            
            
                        
            
    
        end
        
        %%
        function btn_manual_callback(main, varargin)
            
            selectedRow = getSelectedItem(main, 'list_stages');
            
            stageToGet = ['stage' num2str(main.stageTracking{selectedRow,1})];
            
            stageType = obtainStageType (main.(stageToGet).stagePoles, main.(stageToGet).stageZeros);
                       
            selectedCell = get(get(main.handles.radioGroup_cells,'SelectedObject'),'Tag');
            
            
            switch selectedCell

                case 'radio_sallenKey'
                    
                    main.(stageToGet).stageCircuit = 1;
                    error = 1;
                    
                    
                    [R1, R2, C1, C2, Ra, Rb, error] = obtainSallenKey(main.(stageToGet), stageType);
                    if error == 0
                        
                    assignValues(main.(stageToGet), stageType, R1, R2, 0, 0, 0, 0, 0, 0, Ra, Rb, C1, C2, 0);
                    
                    showImage(main, 1, stageType);
                    showComponentValues(main, main.(stageToGet));
                    showSensibility(main, main.(stageToGet));
                    else
                        errordlg('Error: No se puede implementar la etapa con la celda elegida (Sallen Key)', 'Error');
                    end
                    
                case 'radio_rauch'
                    
                    main.(stageToGet).stageCircuit = 4;
                    error = 1;
                    
                    if stageType == 4
                        [C1, C2, C3, R1, Ra, Rb, error] = obtainRauch(main.(stageToGet), stageType);
                        
                        if error == 0
                            assignValues(main.(stageToGet), stageType, R1, R1, 0, 0, 0, 0, 0, 0, Ra, Rb, C1, C2, C3);
                    
                            showImage(main, 4, stageType);
                        else
                            errordlg('Error: No se puede implementar la etapa con la celda elegida (Universal)', 'Error');
                        end
                     elseif stageType == 1
                        [R1, R2, R3, C1, Ra, Rb, error] = obtainRauch(main.(stageToGet), stageType);
                        
                        if error == 0
                            assignValues(main.(stageToGet), stageType, R1, R2, R3, 0, 0, 0, 0, 0, Ra, Rb, C1, C1, 0);
                    
                            showImage(main, 4, stageType);
                        else
                            errordlg('Error: No se puede implementar la etapa con la celda elegida (Universal)', 'Error');
                        end
                    else
                        errordlg('Error: No se puede implementar la etapa con la celda elegida (Rauch)', 'Error');
                    end
                    if error == 0
                    showComponentValues(main, main.(stageToGet));
                    showSensibility(main, main.(stageToGet));
                    end
                case 'radio_sedra'
                    
                    main.(stageToGet).stageCircuit = 2;
                    error = 1;

                    [R1, R2, Rb, Comp1, Comp21, Comp22, Comp3, Comp41, Comp42, error]=obtainSedra (main.(stageToGet), stageType);
                    
                    if error == 0

                        if stageType == 2
                        
                        assignValues(main.(stageToGet), stageType, R1, R2, Comp3, Comp22, Comp21, 0,0, 0, 0, Rb, Comp42, Comp41, Comp1);
                   
                        showImage(main, 2, stageType);

                        elseif stageType == 3
                        
                        assignValues(main.(stageToGet), stageType, R1, R2, Comp42, Comp41, Comp1, 0, 0, 0, 0, Rb, Comp3, Comp22, Comp21);
                        
                        showImage(main, 2, stageType);

                        end
                        
                        if error == 0
                        showComponentValues(main, main.(stageToGet));
                        showSensibility(main, main.(stageToGet));
                        end
                        
                    else
                        errordlg('Error: No se puede implementar la etapa con la celda elegida (Sedra)', 'Error');
                    end
                    
                case 'radio_universal'
                    error = 1;
                    
                    main.(stageToGet).stageCircuit = 3;
                    
                    
                    [componentArray, error]=obtainUniversal(main.(stageToGet),stageType);
                    if error == 0
                    R1=componentArray(1);
                    R2=componentArray(2);
                    R3=componentArray(3);
                    R4=componentArray(4);
                    R5=componentArray(5);
                    R6=componentArray(6);
                    R7=componentArray(7);
                    R8=componentArray(8);
                    C1=componentArray(9);
                    C2=componentArray(10);
                    
                    assignValues(main.(stageToGet), stageType, R1, R2, R3, R4, R5, R6, R7, R8, 0, 0, C1, C2, 0);
                    
                    showImage(main, 3, stageType);
                    showComponentValues(main, main.(stageToGet));
                    showSensibility(main, main.(stageToGet));
                    else
                        errordlg('Error: No se puede implementar la etapa con la celda elegida (Universal)', 'Error');
                    end
                    
            end
            
            if error == 0
            main.assignedAmount = main.assignedAmount + 1;
            
            main.assignedStageTracking{main.assignedAmount,1} = main.stageTracking{selectedRow,1};   
            main.assignedStageTracking{main.assignedAmount,2} = main.stageTracking{selectedRow,2};
            
                        
            for index = selectedRow : main.stageAmount-1
            main.stageTracking{index,1}=main.stageTracking{index+1,1};
            main.stageTracking{index,2}=main.stageTracking{index+1,2};
            end
            main.stageAmount = main.stageAmount - 1;
            
            updateCellList(main);
            
            updateStageList(main);
            
            if main.filterGain{1} ~= 1 && main.filterGain{2}==0
               stringToList = get(main.handles.list_stages, 'String');
               listSize = max(size(stringToList));
               stringToList{listSize+1} = 'Independent gain';
               set(main.handles.list_stages,'Value',1); %Avoids "error" when repopulating LISTBOX
               set(main.handles.list_stages, 'String', stringToList);   % Repopulates listbox
           end
            
            stringToList = {};
            set(main.handles.list_actualPoles, 'String', stringToList);
            set(main.handles.list_actualZeros, 'String', stringToList);
            end
            
            
            
        end
        
        %%
        function btn_deleteCell_callback(main, varargin);
            
            selectedRow = getSelectedItem(main, 'list_cells');
            if selectedRow < main.assignedAmount+1
            stageToGet = ['stage' num2str(main.stageTracking{selectedRow,1})];  %Cambie por assigned
            
            main.stageAmount = main.stageAmount + 1;
            main.assignedAmount = main.assignedAmount - 1;
            
            main.stageTracking{main.stageAmount,1} = main.assignedStageTracking{selectedRow,1};
            main.stageTracking{main.stageAmount,2} = main.assignedStageTracking{selectedRow,2};
            
            for index = selectedRow : main.assignedAmount %Ojo cambie por assigned la izq
                main.assignedStageTracking{index,1} = main.assignedStageTracking{index+1,1};
                main.assignedStageTracking{index,2} = main.assignedStageTracking{index+1,2};
            end
            
            else
            
            main.filterGain{2} = 0;
            
            end
            updateStageList(main);
            updateCellList(main);
            if main.filterGain{1} ~= 1 && main.filterGain{2}==0
               stringToList = get(main.handles.list_stages, 'String');
               listSize = size(stringToList);
               listSize = listSize(1);
               stringToList{listSize+1} = 'Independent gain';
               set(main.handles.list_stages,'Value',1); %Avoids "error" when repopulating LISTBOX
               set(main.handles.list_stages, 'String', stringToList);   % Repopulates listbox
            end
            
        end
        %%
        function btn_match_callback(main, varargin)
            
            radioSelected = get(get(main.handles.radioGroup_components,'SelectedObject'),'Tag');
            
            CalcError = 0;
            
            
            switch radioSelected
                case 'radio_R1'
                    R1 = str2num(get(main.handles.txt_R1,'String'));
                    if R1 ~= Inf
                        [result, error] = matchable(R1);
                    else
                        CalcError = 1;
                    end
                case 'radio_R2'
                    R2 = str2num(get(main.handles.txt_R2,'String'));
                    if R2 ~= Inf
                        [result, error] = matchable(R2);
                    else
                        CalcError = 1;
                    end
                case 'radio_R3'
                    R3 = str2num(get(main.handles.txt_R3,'String'));
                    if R3 ~= Inf
                        [result, error] = matchable(R3);
                    else
                        CalcError = 1;
                    end
                case 'radio_R4'
                    R4 = str2num(get(main.handles.txt_R4,'String'));
                    if R4 ~= Inf
                        [result, error] = matchable(R4);
                    else
                        CalcError = 1;
                    end
                case 'radio_R5'
                    R5 = str2num(get(main.handles.txt_R5,'String'));
                    if R5 ~= Inf
                        [result, error] = matchable(R5);
                    else
                        CalcError = 1;
                    end
                case 'radio_R6'
                    R6 = str2num(get(main.handles.txt_R6,'String'));
                    if R6 ~= Inf
                        [result, error] = matchable(R6);
                    else
                        CalcError = 1;
                    end
                case 'radio_R7'
                    R7 = str2num(get(main.handles.txt_R7,'String'));
                    if R7 ~= Inf
                        [result, error] = matchable(R7);
                    else
                        CalcError = 1;
                    end
                case 'radio_R8'
                    R8 = str2num(get(main.handles.txt_R8,'String'));
                    if R8 ~= Inf
                        [result, error] = matchable(R8);
                    else
                        CalcError = 1;
                    end
                case 'radio_Ra'
                    Ra = str2num(get(main.handles.txt_Ra,'String'));
                    if Ra ~= Inf
                        [result, error] = matchable(Ra);
                    else
                        CalcError = 1;
                    end
                case 'radio_Rb'
                    Rb = str2num(get(main.handles.txt_Rb,'String'));
                    if Rb ~= Inf
                        [result, error] = matchable(Rb);
                    else
                        CalcError = 1;
                    end
                case 'radio_C1'
                    C1 = str2num(get(main.handles.txt_R1,'String'));
                    if C1 ~= Inf
                        [result, error] = matchableC(C1);
                    else
                        CalcError = 1;
                    end
                case 'radio_C2'
                    C2 = str2num(get(main.handles.txt_R1,'String'));
                    if C2 ~= Inf
                        [result, error] = matchableC(C2);
                    else
                        CalcError = 1;
                    end
                case 'radio_C3'
                    C3 = str2num(get(main.handles.txt_C3,'String'));
                    if C3 ~= Inf
                        [result, error] = matchableC(C3);
                    else
                        CalcError = 1;
                    end
            end
            
            
            if CalcError == 0
                if result(3) == 3
                    msgbox(sprintf(['R = ' num2str(result(1)) '\n+\nR = ' num2str(result(2)) '\n\nerror: ' num2str(error) '%']));
                elseif result(3) == 1
                    msgbox(sprintf(['R = ' num2str(result(1)) '\n//\nR = ' num2str(result(2)) '\n\nerror: ' num2str(error) '%']));
                elseif result(3) == 0
                    msgbox(sprintf(['R = ' num2str(result(1)) '\n+\nR = ' num2str(result(2)) '\n\nerror: ' num2str(error) '%']));
                end
            end
            
        end
        %%
        function list_cells_callback(main, varargin)
            
            selectedRow = getSelectedItem(main, 'list_cells');
            
            if selectedRow == main.assignedAmount+1
                if strcmp(main.filterGain{3}, 'inversor' )
                    showImage(main, 7, 0);
                    showComponentValues(main, 0);
                elseif strcmp(main.filterGain{3}, 'no inversor' )
                    showImage(main, 8, 0);
                    showComponentValues(main, 0);
                end
                
            else
            
            stageToGet = ['stage' num2str(main.assignedStageTracking{selectedRow,1})];
            
            stageID = main.assignedStageTracking{selectedRow,1};
            main.currentStageID = stageID;
            
            stageType = obtainStageType (main.(stageToGet).stagePoles, main.(stageToGet).stageZeros);
            
            showImage(main, main.(stageToGet).stageCircuit, stageType);
            showComponentValues(main, main.(stageToGet));
            showSensibility(main, main.(stageToGet));
            
            main.actualPoles = max(size(main.(stageToGet).stagePoles));
            main.actualZeros = max(size(main.(stageToGet).stageZeros));
           
            updateActualPolesList(main, main.currentStageID);
            updateActualZerosList(main, main.currentStageID);
           
            for index = 1 : (main.assignedAmount+main.stageAmount)
               
                if main.plotTracking{index, 5} == stageID
                    set(main.plotTracking{index, 1}, 'Visible', 'On');
                    set(main.plotTracking{index, 2}, 'Visible', 'On');
                    set(main.plotTracking{index, 3}, 'Visible', 'On');
                    set(main.plotTracking{index, 4}, 'Visible', 'On');
                else
                    set(main.plotTracking{index, 1}, 'Visible', 'Off');
                    set(main.plotTracking{index, 2}, 'Visible', 'Off');
                    set(main.plotTracking{index, 3}, 'Visible', 'Off');
                    set(main.plotTracking{index, 4}, 'Visible', 'Off');
                end
                    
            end
            end
            
            
        end
        
        %%
        function btn_export_callback(main, varargin)
            
            publish('exportToHTML.m', struct('codeToEvaluate', 'exportToHTML(h.stageTHREE, h.stageTWO)', 'showCode', false));
            msgbox('Data exported');
 
        end
            
        end
        
        
end
